package app.gt.screen.login;

import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ParseException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import app.gt.R;

public class LoginScreen extends ListActivity  {
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	RowData rd;
	static final String[] title = new String[] {
		    "Forgot Password", "Register Now"};
	private Integer[] imgidf = {
			  R.drawable.lock_32,R.drawable.user_add_32};
	private Integer[] imgidb = {
	  R.drawable.forward,R.drawable.forward};
	@Override
	public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.login);
	
Button check = (Button)findViewById(R.id.LoginScreen_Login_Button);
check.setOnClickListener(new OnClickListener() {
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		startActivity(new Intent("app.gt.screen.profile.StartScreen"));
		
	}
});
	
	//listview create
	mInflater = (LayoutInflater) getSystemService(
	Activity.LAYOUT_INFLATER_SERVICE);
	data = new Vector<RowData>();
	for(int i=0;i<title.length;i++){
	try {
	 	rd = new RowData(i,title[i],i);
	    } catch (ParseException e) {
	    	e.printStackTrace();
	   }
	   data.add(rd);
	}
	   CustomAdapter adapter = new CustomAdapter(this, R.layout.list,
	                                     R.id.title, data);
	   setListAdapter(adapter);
	   getListView().setTextFilterEnabled(true);
	}
	   public void onListItemClick(ListView parent, View v, int position,
	                                                                long id) { 
		   if (position==0) {
			   startActivity(new Intent("app.gt.screen.retrievepassword.ForgotPasswordScreen")); 
			
		};
		if (position==1) {
			startActivity(new Intent("app.gt.screen.registration.RegisterScreen"));
		};
	  
	}
	       private class RowData {
	       protected int mIdf;
	       protected int mIdb;
	       protected String mTitle;
	      // protected String mDetail;
	       RowData(int id1,String title,int id2){
	       mIdf=id1;
	       mIdb=id2;
	       mTitle = title;
	     //  mDetail=detail;
	    }
	      
		@Override
	       public String toString() {
	               return mIdf+" "+mTitle+" "+mIdb;
	       }
	}
	  private class CustomAdapter extends ArrayAdapter<RowData> {
	  public CustomAdapter(Context context, int resource,
	                        int textViewResourceId, List<RowData> objects) {               
	 super(context, resource, textViewResourceId, objects);
	}
	      @Override
	       public View getView(int position, View convertView, ViewGroup parent) {   
	       ViewHolder holder = null;
	       TextView title = null;
	      // TextView detail = null;
	       ImageView i11f=null;
	       ImageView i11b=null;
	       RowData rowData= getItem(position);
	       if(null == convertView){
	            convertView = mInflater.inflate(R.layout.list, null);
	            holder = new ViewHolder(convertView);
	            convertView.setTag(holder);
	 }
	             holder = (ViewHolder) convertView.getTag();
	             title = holder.gettitle();
	             title.setText(rowData.mTitle);
	             //detail = holder.getdetail();
	             //detail.setText(rowData.mDetail);                                                     
	             i11f=holder.getImage();
	             i11f.setImageResource(imgidf[rowData.mIdf]);
	             i11b=holder.getImageb();
	             i11b.setImageResource(imgidb[rowData.mIdb]);
	             return convertView;
	}
	            private class ViewHolder {
	            private View mRow;
	            private TextView title = null;
	           // private TextView detail = null;
	            private ImageView i11f=null; 
	            private ImageView i11b=null;
	            public ViewHolder(View row) {
	            mRow = row;
	 }
	         public TextView gettitle() {
	             if(null == title){
	                 title = (TextView) mRow.findViewById(R.id.title);
	                }
	            return title;
	         }     
	        
	        public ImageView getImage() {
	             if(null == i11f){
	                  i11f = (ImageView) mRow.findViewById(R.id.imgf);
	                                      }
	                return i11f
	                ;
	        }
	        public ImageView getImageb() {
	             if(null == i11b){
	                  i11b = (ImageView) mRow.findViewById(R.id.imgb);
	                                      }
	                return i11b;
	        }
	     }
	   }
	
	
	} 